require 'capistrano/recipes/deploy/scm/base'

module Capistrano
  module Deploy
    module SCM

      # Implements the Capistrano SCM interface for using a plain old
      # directory to do deployment. It fakes out all the usual SCM commands
      # so we can use the other infrastructure to copy & deploy a tarball
      class Directory < Base
        # Sets the default command name for this SCM. Users may override this
        # by setting the :scm_command variable.
        default_command "cp"
        
        #TODO: make this work!
        #set :deploy_via, :copy
        
        def checkout(revision, destination)
          not_implemented
        end
        
        def export(revision, destination)
          not_implemented
        end
        
        def copy(revision, destination)
          switches = '-Rp'
          
          scm verbose, verbose, switches, repository, destination
        end

        def head
          nil
        end
        
        def query_revision(revision)
          nil
        end
        
        private
        # If verbose output is requested, return "-v"
        def verbose
          "-v" if variable(:scm_verbose)
        end
        
        def not_implemented
          raise NotImplementedError, "set :deploy_via, :#{variable(:deploy_via)} is not supported. Only :copy"
        end
        
      end
    end #SCM
  end #Deploy
end #Capistrano

module Capistrano
   module Deploy
     module SCM
       
         def self.new(scm, config={})
           scm_const = scm.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
           const_get(scm_const).new(config)
         end
     end
   end
end